<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>perlfaq9 - Web, Email and Networking - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/perlfaq9">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlfaq9.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/perlfaq9">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/perlfaq9">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/perlfaq9">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/perlfaq9">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/perlfaq9">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/perlfaq9">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/perlfaq9">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/perlfaq9">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/perlfaq9">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/perlfaq9">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/perlfaq9">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/perlfaq9">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/perlfaq9">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/perlfaq9">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/perlfaq9">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/perlfaq9">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/perlfaq9">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/perlfaq9">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/perlfaq9">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/perlfaq9">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/perlfaq9">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/perlfaq9">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/perlfaq9">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/perlfaq9">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/perlfaq9">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/perlfaq9">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/perlfaq9">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/perlfaq9">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/perlfaq9">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/perlfaq9">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/perlfaq9">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/perlfaq9">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/perlfaq9">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/perlfaq9">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/perlfaq9">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/perlfaq9">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/perlfaq9">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/perlfaq9">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/perlfaq9">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/perlfaq9">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/perlfaq9">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/perlfaq9">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/perlfaq9">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/perlfaq9">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/perlfaq9">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/perlfaq9">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/perlfaq9">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/perlfaq9">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/perlfaq9">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/perlfaq9">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/perlfaq9">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/perlfaq9">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/perlfaq9">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/perlfaq9">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/perlfaq9">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/perlfaq9">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/perlfaq9">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/perlfaq9">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/perlfaq9">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/perlfaq9">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/perlfaq9">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/perlfaq9">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/perlfaq9">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/perlfaq9">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/perlfaq9">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/perlfaq9">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/perlfaq9">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/perlfaq9">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/perlfaq9">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/perlfaq9">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/perlfaq9">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/perlfaq9">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/perlfaq9">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/perlfaq9">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/perlfaq9">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/perlfaq9">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/perlfaq9">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/perlfaq9">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/perlfaq9">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/perlfaq9">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlfaq9.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/perlfaq9">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/perlfaq9">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/perlfaq9">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/perlfaq9">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/perlfaq9">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/perlfaq9">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/perlfaq9">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/perlfaq9">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/perlfaq9">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/perlfaq9">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/perlfaq9">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/perlfaq9">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/perlfaq9">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/perlfaq9">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/perlfaq9">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/perlfaq9">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/perlfaq9">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/perlfaq9">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/perlfaq9">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/perlfaq9">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/perlfaq9">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/perlfaq9">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/perlfaq9">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/perlfaq9">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/perlfaq9">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/perlfaq9">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/perlfaq9">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/perlfaq9">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/perlfaq9">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/perlfaq9">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/perlfaq9">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/perlfaq9">5.35.1</a>
          <a class="dropdown-item active" href="perlfaq9.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlfaq9.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="perlfaq9.html">perlfaq9</a>
          <div id="more">
            (<a href="perlfaq9.txt">source</a>,
            <a href="https://metacpan.org/pod/perlfaq9">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#VERSION">VERSION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#Should-I-use-a-web-framework?">Should I use a web framework?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#Which-web-framework-should-I-use?">Which web framework should I use?     </a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#What-is-Plack-and-PSGI?">What is Plack and PSGI?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-remove-HTML-from-a-string?">How do I remove HTML from a string?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-extract-URLs?">How do I extract URLs?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-fetch-an-HTML-file?">How do I fetch an HTML file?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-automate-an-HTML-form-submission?">How do I automate an HTML form submission?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-decode-or-create-those-%25-encodings-on-the-web?">How do I decode or create those %-encodings on the web?   </a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-redirect-to-another-page?">How do I redirect to another page?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-put-a-password-on-my-web-pages?">How do I put a password on my web pages?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-make-sure-users-can&#39;t-enter-values-into-a-form-that-causes-my-CGI-script-to-do-bad-things?">How do I make sure users can&#39;t enter values into a form that causes my CGI script to do bad things?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-parse-a-mail-header?">How do I parse a mail header?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-check-a-valid-mail-address?">How do I check a valid mail address?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-decode-a-MIME/BASE64-string?">How do I decode a MIME/BASE64 string?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-find-the-user&#39;s-mail-address?">How do I find the user&#39;s mail address?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-send-email?">How do I send email?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-use-MIME-to-make-an-attachment-to-a-mail-message?">How do I use MIME to make an attachment to a mail message?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-read-email?">How do I read email?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-find-out-my-hostname,-domainname,-or-IP-address?">How do I find out my hostname, domainname, or IP address? </a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-do-I-fetch/put-an-(S)FTP-file?">How do I fetch/put an (S)FTP file?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#How-can-I-do-RPC-in-Perl?">How can I do RPC in Perl?</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlfaq9.html#AUTHOR-AND-COPYRIGHT">AUTHOR AND COPYRIGHT</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="perlfaq9.html#NAME">#</a>NAME</h1>

<p>perlfaq9 - Web, Email and Networking</p>

<h1 id="VERSION"><a class="permalink" href="perlfaq9.html#VERSION">#</a>VERSION</h1>

<p>version 5.20210411</p>

<h1 id="DESCRIPTION"><a class="permalink" href="perlfaq9.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>This section deals with questions related to running web sites, sending and receiving email as well as general networking.</p>

<h2 id="Should-I-use-a-web-framework?"><a class="permalink" href="perlfaq9.html#Should-I-use-a-web-framework?">#</a><a id="Should"></a><a id="Should-I-use-a-web-framework"></a>Should I use a web framework?</h2>

<p>Yes. If you are building a web site with any level of interactivity (forms / users / databases), you will want to use a framework to make handling requests and responses easier.</p>

<p>If there is no interactivity then you may still want to look at using something like <a href="https://metacpan.org/module/Template">Template Toolkit</a> or <a href="./Plack::Middleware::TemplateToolkit.html">Plack::Middleware::TemplateToolkit</a> so maintenance of your HTML files (and other assets) is easier.</p>

<h2 id="Which-web-framework-should-I-use?"><a class="permalink" href="perlfaq9.html#Which-web-framework-should-I-use?">#</a><a id="Which"></a><a id="Which-web-framework-should-I-use"></a>Which web framework should I use?     </h2>

<p>There is no simple answer to this question. Perl frameworks can run everything from basic file servers and small scale intranets to massive multinational multilingual websites that are the core to international businesses.</p>

<p>Below is a list of a few frameworks with comments which might help you in making a decision, depending on your specific requirements. Start by reading the docs, then ask questions on the relevant mailing list or IRC channel.</p>

<dl>

<dt id="Catalyst"><a class="permalink" href="perlfaq9.html#Catalyst">#</a><a href="Catalyst.html">Catalyst</a></dt>
<dd>

<p>Strongly object-oriented and fully-featured with a long development history and a large community and addon ecosystem. It is excellent for large and complex applications, where you have full control over the server.</p>

</dd>
<dt id="Dancer2"><a class="permalink" href="perlfaq9.html#Dancer2">#</a><a href="Dancer2.html">Dancer2</a></dt>
<dd>

<p>Free of legacy weight, providing a lightweight and easy to learn API. Has a growing addon ecosystem. It is best used for smaller projects and very easy to learn for beginners.</p>

</dd>
<dt id="Mojolicious"><a class="permalink" href="perlfaq9.html#Mojolicious">#</a><a href="Mojolicious.html">Mojolicious</a></dt>
<dd>

<p>Self-contained and powerful for both small and larger projects, with a focus on HTML5 and real-time web technologies such as WebSockets.</p>

</dd>
<dt id="Web::Simple"><a class="permalink" href="perlfaq9.html#Web::Simple">#</a><a id="Web"></a><a href="./Web::Simple.html">Web::Simple</a></dt>
<dd>

<p>Strongly object-oriented and minimal, built for speed and intended as a toolkit for building micro web apps, custom frameworks or for tieing together existing Plack-compatible web applications with one central dispatcher.</p>

</dd>
</dl>

<p>All of these interact with or use <a href="Plack.html">Plack</a> which is worth understanding the basics of when building a website in Perl (there is a lot of useful <a href="https://metacpan.org/search?q=plack%3A%3Amiddleware">Plack::Middleware</a>).</p>

<h2 id="What-is-Plack-and-PSGI?"><a class="permalink" href="perlfaq9.html#What-is-Plack-and-PSGI?">#</a><a id="What"></a><a id="What-is-Plack-and-PSGI"></a>What is Plack and PSGI?</h2>

<p><a href="PSGI.html">PSGI</a> is the Perl Web Server Gateway Interface Specification, it is a standard that many Perl web frameworks use, you should not need to understand it to build a web site, the part you might want to use is <a href="Plack.html">Plack</a>.</p>

<p><a href="Plack.html">Plack</a> is a set of tools for using the PSGI stack. It contains <a href="https://metacpan.org/search?q=plack%3A%3Amiddleware">middleware</a> components, a reference server and utilities for Web application frameworks. Plack is like Ruby&#39;s Rack or Python&#39;s Paste for WSGI.</p>

<p>You could build a web site using <a href="Plack.html">Plack</a> and your own code, but for anything other than a very basic web site, using a web framework (that uses <a href="https://plackperl.org">https://plackperl.org</a>) is a better option.</p>

<h2 id="How-do-I-remove-HTML-from-a-string?"><a class="permalink" href="perlfaq9.html#How-do-I-remove-HTML-from-a-string?">#</a><a id="How"></a><a id="How-do-I-remove-HTML-from-a-string"></a>How do I remove HTML from a string?</h2>

<p>Use <a href="./HTML::Strip.html">HTML::Strip</a>, or <a href="./HTML::FormatText.html">HTML::FormatText</a> which not only removes HTML but also attempts to do a little simple formatting of the resulting plain text.</p>

<h2 id="How-do-I-extract-URLs?"><a class="permalink" href="perlfaq9.html#How-do-I-extract-URLs?">#</a><a id="How1"></a><a id="How-do-I-extract-URLs"></a>How do I extract URLs?</h2>

<p><a href="./HTML::SimpleLinkExtor.html">HTML::SimpleLinkExtor</a> will extract URLs from HTML, it handles anchors, images, objects, frames, and many other tags that can contain a URL. If you need anything more complex, you can create your own subclass of <a href="./HTML::LinkExtor.html">HTML::LinkExtor</a> or <a href="./HTML::Parser.html">HTML::Parser</a>. You might even use <a href="./HTML::SimpleLinkExtor.html">HTML::SimpleLinkExtor</a> as an example for something specifically suited to your needs.</p>

<p>You can use <a href="./URI::Find.html">URI::Find</a> or <a href="./URL::Search.html">URL::Search</a> to extract URLs from an arbitrary text document.</p>

<h2 id="How-do-I-fetch-an-HTML-file?"><a class="permalink" href="perlfaq9.html#How-do-I-fetch-an-HTML-file?">#</a><a id="How2"></a><a id="How-do-I-fetch-an-HTML-file"></a>How do I fetch an HTML file?</h2>

<p>(contributed by brian d foy)</p>

<p>The core <a href="./HTTP::Tiny.html">HTTP::Tiny</a> module can fetch web resources and give their content back to you as a string:</p>

<pre><code>use HTTP::Tiny;

my $ua = HTTP::Tiny-&gt;new;
my $html = $ua-&gt;get( &quot;http://www.example.com/index.html&quot; )-&gt;{content};</code></pre>

<p>It can also store the resource directly in a file:</p>

<pre><code>$ua-&gt;mirror( &quot;http://www.example.com/index.html&quot;, &quot;foo.html&quot; );</code></pre>

<p>If you need to do something more complicated, the <a href="./HTTP::Tiny.html">HTTP::Tiny</a> object can be customized by setting attributes, or you can use <a href="./LWP::UserAgent.html">LWP::UserAgent</a> from the libwww-perl distribution or <a href="./Mojo::UserAgent.html">Mojo::UserAgent</a> from the Mojolicious distribution to make common tasks easier. If you want to simulate an interactive web browser, you can use the <a href="./WWW::Mechanize.html">WWW::Mechanize</a> module.</p>

<h2 id="How-do-I-automate-an-HTML-form-submission?"><a class="permalink" href="perlfaq9.html#How-do-I-automate-an-HTML-form-submission?">#</a><a id="How3"></a><a id="How-do-I-automate-an-HTML-form-submission"></a>How do I automate an HTML form submission?</h2>

<p>If you are doing something complex, such as moving through many pages and forms or a web site, you can use <a href="./WWW::Mechanize.html">WWW::Mechanize</a>. See its documentation for all the details.</p>

<p>If you&#39;re submitting values using the GET method, create a URL and encode the form using the <code>www_form_urlencode</code> method from <a href="./HTTP::Tiny.html">HTTP::Tiny</a>:</p>

<pre><code>use HTTP::Tiny;

my $ua = HTTP::Tiny-&gt;new;

my $query = $ua-&gt;www_form_urlencode([ q =&gt; &#39;DB_File&#39;, lucky =&gt; 1 ]);
my $url = &quot;https://metacpan.org/search?$query&quot;;
my $content = $ua-&gt;get($url)-&gt;{content};</code></pre>

<p>If you&#39;re using the POST method, the <code>post_form</code> method will encode the content appropriately.</p>

<pre><code>use HTTP::Tiny;

my $ua = HTTP::Tiny-&gt;new;

my $url = &#39;https://metacpan.org/search&#39;;
my $form = [ q =&gt; &#39;DB_File&#39;, lucky =&gt; 1 ];
my $content = $ua-&gt;post_form($url, $form)-&gt;{content};</code></pre>

<h2 id="How-do-I-decode-or-create-those-%-encodings-on-the-web?"><a class="permalink" href="perlfaq9.html#How-do-I-decode-or-create-those-%25-encodings-on-the-web?">#</a><a id="How4"></a><a id="How-do-I-decode-or-create-those--encodings-on-the-web"></a>How do I decode or create those %-encodings on the web?   </h2>

<p>Most of the time you should not need to do this as your web framework, or if you are making a request, the <a href="LWP.html">LWP</a> or other module would handle it for you.</p>

<p>To encode a string yourself, use the <a href="./URI::Escape.html">URI::Escape</a> module. The <code>uri_escape</code> function returns the escaped string:</p>

<pre><code>my $original = &quot;Colon : Hash # Percent %&quot;;

my $escaped = uri_escape( $original );

print &quot;$escaped\n&quot;; # &#39;Colon%20%3A%20Hash%20%23%20Percent%20%25&#39;</code></pre>

<p>To decode the string, use the <code>uri_unescape</code> function:</p>

<pre><code>my $unescaped = uri_unescape( $escaped );

print $unescaped; # back to original</code></pre>

<p>Remember not to encode a full URI, you need to escape each component separately and then join them together.</p>

<h2 id="How-do-I-redirect-to-another-page?"><a class="permalink" href="perlfaq9.html#How-do-I-redirect-to-another-page?">#</a><a id="How5"></a><a id="How-do-I-redirect-to-another-page"></a>How do I redirect to another page?</h2>

<p>Most Perl Web Frameworks will have a mechanism for doing this, using the <a href="Catalyst.html">Catalyst</a> framework it would be:</p>

<pre><code>$c-&gt;res-&gt;redirect($url);
$c-&gt;detach();</code></pre>

<p>If you are using Plack (which most frameworks do), then <a href="./Plack::Middleware::Rewrite.html">Plack::Middleware::Rewrite</a> is worth looking at if you are migrating from Apache or have URL&#39;s you want to always redirect.</p>

<h2 id="How-do-I-put-a-password-on-my-web-pages?"><a class="permalink" href="perlfaq9.html#How-do-I-put-a-password-on-my-web-pages?">#</a><a id="How6"></a><a id="How-do-I-put-a-password-on-my-web-pages"></a>How do I put a password on my web pages?</h2>

<p>See if the web framework you are using has an authentication system and if that fits your needs.</p>

<p>Alternativly look at <a href="./Plack::Middleware::Auth::Basic.html">Plack::Middleware::Auth::Basic</a>, or one of the other <a href="https://metacpan.org/search?q=plack+auth">Plack authentication</a> options.</p>

<h2 id="How-do-I-make-sure-users-can&#39;t-enter-values-into-a-form-that-causes-my-CGI-script-to-do-bad-things?"><a class="permalink" href="perlfaq9.html#How-do-I-make-sure-users-can&#39;t-enter-values-into-a-form-that-causes-my-CGI-script-to-do-bad-things?">#</a><a id="How7"></a><a id="How-do-I-make-sure-users-cant-enter-values-into-a-form-that-causes-my-CGI-script-to-do-bad-things"></a>How do I make sure users can&#39;t enter values into a form that causes my CGI script to do bad things?</h2>

<p>(contributed by brian d foy)</p>

<p>You can&#39;t prevent people from sending your script bad data. Even if you add some client-side checks, people may disable them or bypass them completely. For instance, someone might use a module such as <a href="LWP.html">LWP</a> to submit to your web site. If you want to prevent data that try to use SQL injection or other sorts of attacks (and you should want to), you have to not trust any data that enter your program.</p>

<p>The <a href="perlsec.html">perlsec</a> documentation has general advice about data security. If you are using the <a href="DBI.html">DBI</a> module, use placeholder to fill in data. If you are running external programs with <code>system</code> or <code>exec</code>, use the list forms. There are many other precautions that you should take, too many to list here, and most of them fall under the category of not using any data that you don&#39;t intend to use. Trust no one.</p>

<h2 id="How-do-I-parse-a-mail-header?"><a class="permalink" href="perlfaq9.html#How-do-I-parse-a-mail-header?">#</a><a id="How8"></a><a id="How-do-I-parse-a-mail-header"></a>How do I parse a mail header?</h2>

<p>Use the <a href="./Email::MIME.html">Email::MIME</a> module. It&#39;s well-tested and supports all the craziness that you&#39;ll see in the real world (comment-folding whitespace, encodings, comments, etc.).</p>

<pre><code>use Email::MIME;

my $message = Email::MIME-&gt;new($rfc2822);
my $subject = $message-&gt;header(&#39;Subject&#39;);
my $from    = $message-&gt;header(&#39;From&#39;);</code></pre>

<p>If you&#39;ve already got some other kind of email object, consider passing it to <a href="./Email::Abstract.html">Email::Abstract</a> and then using its cast method to get an <a href="./Email::MIME.html">Email::MIME</a> object:</p>

<pre><code>my $abstract = Email::Abstract-&gt;new($mail_message_object);
my $email_mime_object = $abstract-&gt;cast(&#39;Email::MIME&#39;);</code></pre>

<h2 id="How-do-I-check-a-valid-mail-address?"><a class="permalink" href="perlfaq9.html#How-do-I-check-a-valid-mail-address?">#</a><a id="How9"></a><a id="How-do-I-check-a-valid-mail-address"></a>How do I check a valid mail address?</h2>

<p>(partly contributed by Aaron Sherman)</p>

<p>This isn&#39;t as simple a question as it sounds. There are two parts:</p>

<p>a) How do I verify that an email address is correctly formatted?</p>

<p>b) How do I verify that an email address targets a valid recipient?</p>

<p>Without sending mail to the address and seeing whether there&#39;s a human on the other end to answer you, you cannot fully answer part <i>b</i>, but the <a href="./Email::Valid.html">Email::Valid</a> module will do both part <i>a</i> and part <i>b</i> as far as you can in real-time.</p>

<p>Our best advice for verifying a person&#39;s mail address is to have them enter their address twice, just as you normally do to change a password. This usually weeds out typos. If both versions match, send mail to that address with a personal message. If you get the message back and they&#39;ve followed your directions, you can be reasonably assured that it&#39;s real.</p>

<p>A related strategy that&#39;s less open to forgery is to give them a PIN (personal ID number). Record the address and PIN (best that it be a random one) for later processing. In the mail you send, include a link to your site with the PIN included. If the mail bounces, you know it&#39;s not valid. If they don&#39;t click on the link, either they forged the address or (assuming they got the message) following through wasn&#39;t important so you don&#39;t need to worry about it.</p>

<h2 id="How-do-I-decode-a-MIME/BASE64-string?"><a class="permalink" href="perlfaq9.html#How-do-I-decode-a-MIME/BASE64-string?">#</a><a id="How10"></a><a id="How-do-I-decode-a-MIME-BASE64-string"></a>How do I decode a MIME/BASE64 string?</h2>

<p>The <a href="./MIME::Base64.html">MIME::Base64</a> package handles this as well as the MIME/QP encoding. Decoding base 64 becomes as simple as:</p>

<pre><code>use MIME::Base64;
my $decoded = decode_base64($encoded);</code></pre>

<p>The <a href="./Email::MIME.html">Email::MIME</a> module can decode base 64-encoded email message parts transparently so the developer doesn&#39;t need to worry about it.</p>

<h2 id="How-do-I-find-the-user&#39;s-mail-address?"><a class="permalink" href="perlfaq9.html#How-do-I-find-the-user&#39;s-mail-address?">#</a><a id="How11"></a><a id="How-do-I-find-the-users-mail-address"></a>How do I find the user&#39;s mail address?</h2>

<p>Ask them for it. There are so many email providers available that it&#39;s unlikely the local system has any idea how to determine a user&#39;s email address.</p>

<p>The exception is for organization-specific email (e.g. foo@yourcompany.com) where policy can be codified in your program. In that case, you could look at $ENV{USER}, $ENV{LOGNAME}, and getpwuid($&lt;) in scalar context, like so:</p>

<pre><code>my $user_name = getpwuid($&lt;)</code></pre>

<p>But you still cannot make assumptions about whether this is correct, unless your policy says it is. You really are best off asking the user.</p>

<h2 id="How-do-I-send-email?"><a class="permalink" href="perlfaq9.html#How-do-I-send-email?">#</a><a id="How12"></a><a id="How-do-I-send-email"></a>How do I send email?</h2>

<p>Use the <a href="./Email::Stuffer.html">Email::Stuffer</a> module, like so:</p>

<pre><code># first, create your message
my $message = Email::Stuffer-&gt;from(&#39;you@example.com&#39;)
                            -&gt;to(&#39;friend@example.com&#39;)
                            -&gt;subject(&#39;Happy birthday!&#39;)
                            -&gt;text_body(&quot;Happy birthday to you!\n&quot;);

$message-&gt;send_or_die;</code></pre>

<p>By default, <a href="./Email::Sender::Simple.html">Email::Sender::Simple</a> (the <code>send</code> and <code>send_or_die</code> methods use this under the hood) will try <code>sendmail</code> first, if it exists in your $PATH. This generally isn&#39;t the case. If there&#39;s a remote mail server you use to send mail, consider investigating one of the Transport classes. At time of writing, the available transports include:</p>

<dl>

<dt id="Email::Sender::Transport::Sendmail"><a class="permalink" href="perlfaq9.html#Email::Sender::Transport::Sendmail">#</a><a id="Email"></a><a href="./Email::Sender::Transport::Sendmail.html">Email::Sender::Transport::Sendmail</a></dt>
<dd>

<p>This is the default. If you can use the <a href="http://man.he.net/man1/mail">mail(1)</a> or <a href="http://man.he.net/man1/mailx">mailx(1)</a> program to send mail from the machine where your code runs, you should be able to use this.</p>

</dd>
<dt id="Email::Sender::Transport::SMTP"><a class="permalink" href="perlfaq9.html#Email::Sender::Transport::SMTP">#</a><a id="Email1"></a><a href="./Email::Sender::Transport::SMTP.html">Email::Sender::Transport::SMTP</a></dt>
<dd>

<p>This transport contacts a remote SMTP server over TCP. It optionally uses TLS or SSL and can authenticate to the server via SASL.</p>

</dd>
</dl>

<p>Telling <a href="./Email::Stuffer.html">Email::Stuffer</a> to use your transport is straightforward.</p>

<pre><code>$message-&gt;transport($email_sender_transport_object)-&gt;send_or_die;</code></pre>

<h2 id="How-do-I-use-MIME-to-make-an-attachment-to-a-mail-message?"><a class="permalink" href="perlfaq9.html#How-do-I-use-MIME-to-make-an-attachment-to-a-mail-message?">#</a><a id="How13"></a><a id="How-do-I-use-MIME-to-make-an-attachment-to-a-mail-message"></a>How do I use MIME to make an attachment to a mail message?</h2>

<p><a href="./Email::MIME.html">Email::MIME</a> directly supports multipart messages. <a href="./Email::MIME.html">Email::MIME</a> objects themselves are parts and can be attached to other <a href="./Email::MIME.html">Email::MIME</a> objects. Consult the <a href="./Email::MIME.html">Email::MIME</a> documentation for more information, including all of the supported methods and examples of their use.</p>

<p><a href="./Email::Stuffer.html">Email::Stuffer</a> uses <a href="./Email::MIME.html">Email::MIME</a> under the hood to construct messages, and wraps the most common attachment tasks with the simple <code>attach</code> and <code>attach_file</code> methods.</p>

<pre><code>Email::Stuffer-&gt;to(&#39;friend@example.com&#39;)
              -&gt;subject(&#39;The file&#39;)
              -&gt;attach_file(&#39;stuff.csv&#39;)
              -&gt;send_or_die;</code></pre>

<h2 id="How-do-I-read-email?"><a class="permalink" href="perlfaq9.html#How-do-I-read-email?">#</a><a id="How14"></a><a id="How-do-I-read-email"></a>How do I read email?</h2>

<p>Use the <a href="./Email::Folder.html">Email::Folder</a> module, like so:</p>

<pre><code>use Email::Folder;

my $folder = Email::Folder-&gt;new(&#39;/path/to/email/folder&#39;);
while(my $message = $folder-&gt;next_message) {
  # next_message returns Email::Simple objects, but we want
  # Email::MIME objects as they&#39;re more robust
  my $mime = Email::MIME-&gt;new($message-&gt;as_string);
}</code></pre>

<p>There are different classes in the <a href="./Email::Folder.html">Email::Folder</a> namespace for supporting various mailbox types. Note that these modules are generally rather limited and only support <b>reading</b> rather than writing.</p>

<h2 id="How-do-I-find-out-my-hostname,-domainname,-or-IP-address?"><a class="permalink" href="perlfaq9.html#How-do-I-find-out-my-hostname,-domainname,-or-IP-address?">#</a><a id="How15"></a><a id="How-do-I-find-out-my-hostname-domainname-or-IP-address"></a>How do I find out my hostname, domainname, or IP address? </h2>

<p>(contributed by brian d foy)</p>

<p>The <a href="./Net::Domain.html">Net::Domain</a> module, which is part of the Standard Library starting in Perl 5.7.3, can get you the fully qualified domain name (FQDN), the host name, or the domain name.</p>

<pre><code>use Net::Domain qw(hostname hostfqdn hostdomain);

my $host = hostfqdn();</code></pre>

<p>The <a href="./Sys::Hostname.html">Sys::Hostname</a> module, part of the Standard Library, can also get the hostname:</p>

<pre><code>use Sys::Hostname;

$host = hostname();</code></pre>

<p>The <a href="./Sys::Hostname::Long.html">Sys::Hostname::Long</a> module takes a different approach and tries harder to return the fully qualified hostname:</p>

<pre><code>use Sys::Hostname::Long &#39;hostname_long&#39;;

my $hostname = hostname_long();</code></pre>

<p>To get the IP address, you can use the <code>gethostbyname</code> built-in function to turn the name into a number. To turn that number into the dotted octet form (a.b.c.d) that most people expect, use the <code>inet_ntoa</code> function from the <a href="Socket.html">Socket</a> module, which also comes with perl.</p>

<pre><code>use Socket;

my $address = inet_ntoa(
    scalar gethostbyname( $host || &#39;localhost&#39; )
);</code></pre>

<h2 id="How-do-I-fetch/put-an-(S)FTP-file?"><a class="permalink" href="perlfaq9.html#How-do-I-fetch/put-an-(S)FTP-file?">#</a><a id="How16"></a><a id="How-do-I-fetch-put-an-S-FTP-file"></a>How do I fetch/put an (S)FTP file?</h2>

<p><a href="./Net::FTP.html">Net::FTP</a>, and <a href="./Net::SFTP.html">Net::SFTP</a> allow you to interact with FTP and SFTP (Secure FTP) servers.</p>

<h2 id="How-can-I-do-RPC-in-Perl?"><a class="permalink" href="perlfaq9.html#How-can-I-do-RPC-in-Perl?">#</a><a id="How17"></a><a id="How-can-I-do-RPC-in-Perl"></a>How can I do RPC in Perl?</h2>

<p>Use one of the RPC modules( <a href="https://metacpan.org/search?q=RPC">https://metacpan.org/search?q=RPC</a> ).</p>

<h1 id="AUTHOR-AND-COPYRIGHT"><a class="permalink" href="perlfaq9.html#AUTHOR-AND-COPYRIGHT">#</a><a id="AUTHOR"></a>AUTHOR AND COPYRIGHT</h1>

<p>Copyright (c) 1997-2010 Tom Christiansen, Nathan Torkington, and other authors as noted. All rights reserved.</p>

<p>This documentation is free; you can redistribute it and/or modify it under the same terms as Perl itself.</p>

<p>Irrespective of its distribution, all code examples in this file are hereby placed into the public domain. You are permitted and encouraged to use this code in your own programs for fun or for profit as you see fit. A simple comment in the code giving credit would be courteous but is not required.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
